package com.erdos.core.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.erdos.common.service.BaseCRUDService;
import com.erdos.core.dao.RefTableDetailDao;
import com.erdos.core.entity.RefTableDetail;
import com.erdos.core.service.RefTableDetailService;

public class RefTableDetailServiceImpl extends BaseCRUDService<RefTableDetail> implements
		RefTableDetailService {
	private static final Log logger = LogFactory.getLog(RefTableDetailServiceImpl.class);
	private RefTableDetailDao refTableDetailDao ;

	
	public RefTableDetailDao getRefTableDetailDao() {
		return refTableDetailDao;
	}

	public void setRefTableDetailDao(RefTableDetailDao refTableDetailDao) {
		this.refTableDetailDao = refTableDetailDao;
	}


	/**
	 * 检查ReferenceTableDetail表中是否有重复记录
	 * @param refTableId 		ReferenceTableID字段的值
	 * @param key1				主键列1的值
	 * @param key2				主键列2的值
	 * @return						true/false
	 * @author LvXiaoGuang
	 * @since  2008-7-28
	 */
	public boolean checkDetailUnique(String refTableId, String key1, String key2) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("refTableId", refTableId);
		params.put("key1Value", key1);
		
		//如果key2Value为null 说明ReferenceTable表中无此列 则不添加此查询条件
		if(key2!=null){
			params.put("key2Value", key2);
		}
		logger.debug("check Reference Table Detail Unique...");
		RefTableDetail refDetailEntity = null;
		if (StringUtils.isNotEmpty(refTableId)) {
			refDetailEntity = getRefTableDetailDao().findUniqueByParams(params) ;
			if (refDetailEntity != null) {
				return false;
			} else {
				return true;
			}
		}else{
			return true;
		}
	}
}
